import React from 'react'
import {HashRouter, Route, Routes,Navigate } from 'react-router-dom'
import Login from '../views/Login/Login'
import Manage from '../views/manage/Manage'
import NotFound from '../views/NotFound'
import Home from '../views/manage/Home'
import UserList from '../views/manage/userManage/list'
import PowerList from '../views/manage/powerManage/PowerList'
import CharacterList from '../views/manage/powerManage/CharacterList'
export default function IndeRouter() {
  return (
    <HashRouter>
        <Routes>
            <Route path="/" element={<RequireAuth>
                    <Manage/>
                </RequireAuth>}>
              <Route index element={<Home/>}></Route>
              <Route path="home" element={<Home/>}></Route>
              <Route path="user-manage/list" element={<UserList/>}></Route>
              <Route path="power-manage/power-list" element={<PowerList/>}></Route>
              <Route path="power-manage/charactor-list" element={<CharacterList/>}></Route>        
            </Route>
            <Route path="/login" element={<Login/>}></Route>
            <Route path="*" element={<NotFound/>}></Route>
        </Routes>
    </HashRouter>
  )
}

function RequireAuth({children}){
    const isLogin=localStorage.getItem('token')
    return isLogin?children:<Navigate to="/login"/>
}

